{% macro render_pagination(pagination, endpoint) %}
{% if pagination %}
<nav aria-label="Page navigation">
<ul class="pagination">
    {% if pagination.pages>1 %}
    <li><a href="{{url_for(endpoint,page=1)}}">首页</a></li>
    {% endif %}

    {% if pagination.has_prev %}
    <li><a href="{{url_for(endpoint,page=pagination.prev_num)}}">上一页</a></li>
    {% else %}
    <li class="disabled"><a href="#">上一页</a></li>
    {% endif %}

    {% if pagination.page > 2 and pagination.pages > 4 and pagination.page < pagination.pages-2 %}
     {% for num in range(1,6) %}
        {% set page=pagination.page-3+num %}
       {% if page==pagination.page %}
          <li class="active"><a href="{{url_for(endpoint,page=page)}}">{{page}}</a></li>
      {% else %}
          <li><a href="{{url_for(endpoint,page=page)}}">{{page}}</a></li>
      {% endif %}

     {% endfor %}
    {% elif pagination.page > 2 and pagination.pages > 4 and pagination.page >= pagination.pages-2 %}
    {% for num in range(1,6) %}
        {% set page=pagination.pages-5+num %}
       {% if page==pagination.page %}
          <li class="active"><a href="{{url_for(endpoint,page=page)}}">{{page}}</a></li>
      {% else %}
          <li><a href="{{url_for(endpoint,page=page)}}">{{page}}</a></li>
      {% endif %}
     {% endfor %}
    {% else %}
    {%- for page in pagination.iter_pages() %}
      {% if loop.index0<5 %}
      {% if page==pagination.page %}
          <li class="active"><a href="{{url_for(endpoint,page=page)}}">{{page}}</a></li>
      {% else %}
          <li><a href="{{url_for(endpoint,page=page)}}">{{page}}</a></li>
      {% endif %}
      {% endif %}
    {%- endfor %}
    {% endif %}

    {% if pagination.has_next %}
    <li><a href="{{url_for(endpoint,page=pagination.next_num)}}">下一页</a></li>
    {% else %}
    <li class="disabled"><a href="#">下一页</a></li>
    {% endif %}

    {% if pagination.pages>1 %}
    <li><a href="{{url_for(endpoint,page=pagination.pages)}}">尾页</a></li>
    {% endif %}
</ul>
</nav>
{% endif %}
{% endmacro %}